package com.baizhiedu.rsm.service.impl;

import com.baizhiedu.rsm.dao.StudentMessageDao;
import com.baizhiedu.rsm.entity.StudentMessage;
import com.baizhiedu.rsm.service.UserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lby
 */
@Service
public class UserLoginServiceImpl implements UserLoginService {
    @Autowired
    private StudentMessageDao studentMessageDao;

    @Override
    public Map login(String xsphone, String xspassword) {
        HashMap<Object, Object> map = new HashMap<>(2);
        StudentMessage studentMessage = studentMessageDao.selectByPhone(xsphone);
        if(studentMessage != null){
            if("123456".equals(xspassword)){
                map.put("login",true);
                map.put("user",studentMessage);
            }else {
                map.put("login",false);
            }
        }else {
            map.put("login",false);
        }

        return map;
    }

    @Override
    public Boolean regist(StudentMessage studentMessage) {
        studentMessage.setSchedule("5");
        studentMessage.setPayment("是");
        studentMessage.setRbtime(new Date());
        try {
            studentMessageDao.insert(studentMessage);
            return true;
        }catch (Exception e){
            return false;
        }
    }
}
